<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>学生登录页</title>
    <meta content="particles.js is a lightweight JavaScript library for creating particles." name="description">
    <meta content="Vincent Garreau" name="author"/>
    <meta content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"
          name="viewport">
    <link href="../../static/css/style.css" media="screen" rel="stylesheet" th:href="@{/static/css/style.css}">
    <link href="../../static/css/reset.css" rel="stylesheet" th:href="@{/static/css/reset.css}" type="text/css"/>
    <script src="../../static/js/md5.min.js" th:src="@{/static/js/md5.min.js}"></script>
    <!--<script src="https://cdn.bootcss.com/blueimp-md5/2.10.0/js/md5.min.js"></script>-->

</head>
<body>
<div id="particles-js">
    <form method="post" onsubmit="return check()" th:action="@{/user/student}">
        <div class="login">
            <div class="login-top">
                登录
            </div>
            <p style="color: red" th:if="${not #strings.isEmpty(msg)}" th:text="${msg}"></p>
            <div class="login-center clearfix">
                <div class="login-center-img"><img src="../../static/img/name.png" th:src="@{/static/img/name.png}"/>
                </div>
                <div class="login-center-input">
                    <input id="username" name="username" onblur="this.placeholder='请输入您的用户名'"
                           onfocus="this.placeholder=''"
                           placeholder="请输入您的用户名" type="text"/>
                    <div class="login-center-input-text">用户名</div>
                </div>
            </div>
            <div class="login-center clearfix">
                <div class="login-center-img">
                    <img src="../../static/img/password.png" th:src="@{/static/img/password.png}"/>
                </div>
                <div class="login-center-input">
                    <input id="pwd" onblur="this.placeholder='请输入您的密码'" onfocus="this.placeholder=''"
                           placeholder="请输入您的密码" type="password" value=""/>
                    <input id="md5-pwd" name="pwd" type="hidden">
                    <div class="login-center-input-text">密码</div>
                </div>
            </div>
            <input class="login-button" type="submit" value="登录">
        </div>
    </form>

    <div class="sk-rotating-plane"></div>
</div>

<script src="../../static/js/particles.min.js" th:src="@{/static/js/particles.min.js}"></script>
<script src="../../static/js/app.js" th:src="@{/static/js/app.js}"></script>
<script type="text/javascript">
    function check() {
        let username = document.getElementById('username');
        let pwd = document.getElementById('pwd');
        let pwd_md5 = document.getElementById('md5-pwd');
        if (username.value != null && pwd.value != null && pwd.value !== "") {
            console.log(username.value);
            pwd_md5.value = md5(pwd.value);
            console.log(pwd_md5.value);
        } else {
            alert("请输入密码");
        }
        return true;
    }

    function hasClass(elem, cls) {
        cls = cls || '';
        if (cls.replace(/\s/g, '').length === 0) return false; //当cls没有参数时，返回false
        return new RegExp(' ' + cls + ' ').test(' ' + elem.className + ' ');
    }

    function addClass(ele, cls) {
        if (!hasClass(ele, cls)) {
            ele.className = ele.className === '' ? cls : ele.className + ' ' + cls;
        }
    }

    function removeClass(ele, cls) {
        if (hasClass(ele, cls)) {
            var newClass = ' ' + ele.className.replace(/[\t\r\n]/g, '') + ' ';
            while (newClass.indexOf(' ' + cls + ' ') >= 0) {
                newClass = newClass.replace(' ' + cls + ' ', ' ');
            }
            ele.className = newClass.replace(/^\s+|\s+$/g, '');
        }
    }

    document.querySelector(".login-button").onclick = function (elementId) {
        addClass(document.querySelector(".login"), "active")
        setTimeout(function () {
            addClass(document.querySelector(".sk-rotating-plane"), "active")
            document.querySelector(".login").style.display = "none"
        }, 800)
        setTimeout(function () {
            removeClass(document.querySelector(".login"), "active")
            removeClass(document.querySelector(".sk-rotating-plane"), "active")
            document.querySelector(".login").style.display = "block"
            alert("登录成功")

        }, 5000)
    }

</script>
</body>
</html>